$(document)
  .ready(function() {

    $('.filter.menu .item')
      .tab()
    ;
    
    $('.ui.menu .item')
      .on('click', (function() {
      
       $(this)
            .removeClass('active item')
            .removeClass('item')
            .addClass('header item')
            .closest('.ui.menu')
          ;
      }))
    ;

    $('.ui.rating')
      .rating({
        clearable: true
      })
    ;
   var $accordion     = $('.ui.accordion');
   
   $accordion
  .accordion()
  ;
  
  var $menuAccordion = $('.ui.menu.accordion')
  var $checkbox      = $('.ui.checkbox');
  
  $menuAccordion
    .accordion({
     exclusive: true
    })
  ;
  
  $checkbox
    .checkbox()
  ;
  

$('.ui.form')
.form()
;

    $('.ui.sidebar')
      .sidebar('attach events', '.launch.button')
     
    ;

    $('.ui.dropdown')
      .dropdown()
    ;

  })
                 
;

$(function(){
   $("#sortable1").sortable({
  	items: 'li',
  	containment: 'parent'
  });

});


(function ($) {
//  jQuery.expr[':'].Contains = function(a,i,m){
//      return (a.textContent || a.innerText || "").toUpperCase().indexOf(m[3].toUpperCase())>=0;
//  };

  function filterList(header, list) {
    var form = $("<form>").attr({"class":"filterform","action":"#"}),
        input = $("<input>").attr({"class":"filterinput","type":"text"});

    
    
    var input1 = document.getElementById("searchName");
    var input2 = document.getElementById("searchStatus");
    var input3 = document.getElementById("searchPrioriter");
    var input4 = document.getElementById("searchAssign");
    var input5 = document.getElementById("searchTag");
    var input6 = document.getElementById("searchDueDate");
    var input7 = document.getElementById("searchPastDate");
//    $(input1).attr({"class":"filterinput","type":"text"});
//    $(form).append(input1).appendTo(header);
     
    $(input1)
      .change( function () {
        var filter = $(this).val();
//        if(filter) {

          $('.todo_text2').hide(); 
          getFields("todo_item", filter, "=");
          
          if (filter == "") 
        {
         location.reload();  
        } 
        
//          $matches = $(list).find('a:Contains(' + filter + ')').parent();
//          $('.todo_item', list).not($matches).slideUp();
//          $matches.slideDown();
//
//        } else {
//          $(list).find("span").slideDown();
//        }
//        return false;
        
      })
      
    .keyup( function () {
        $(this).change();
        
        
//    })
//    
//    .resize(function () {
//        
//location.reload();

    });
    
     $(input2)
      .change( function () {
        var filter = $(this).val();
          $('.todo_text2').hide(); 
          getFields("todo_status", filter, "LIKE");    
          if (filter == "") { location.reload(); }})
      
    .keyup( function () {$(this).change();});  
    
   
    $(input3)
      .change( function () {
        var filter = $(this).val();
          $('.todo_text2').hide(); 
          getFields("todo_prioriter", filter, "=");    
          if (filter == "") { location.reload(); }})
      
    .keyup( function () {$(this).change();}); 
    
   $(input4)
      .change( function () {
        var filter = $(this).val();
          $('.todo_text2').hide(); 
          getFields("todo_assign", filter, "=");    
          if (filter == "") { location.reload(); }})
      
    .keyup( function () {$(this).change();}); 
    
    $(input5)
      .change( function () {
        var filter = $(this).val();
          $('.todo_text2').hide(); 
          getFields("todo_tag", filter, "=");    
          if (filter == "") { location.reload(); }})
      
    .keyup( function () {$(this).change();}); 
    
   $(input6)
      .change( function () {
        var filter = $(this).val();
          $('.todo_text2').hide(); 
          getFields("todo_due_date", filter, "=");    
          if (filter == "") { location.reload(); }})
      
    .keyup( function () {$(this).change();}); 
    
    $(input7)
      .change( function () {
        var filter = $(this).val();
          $('.todo_text2').hide(); 
          getFields("todo_past_date", filter, "=");    
          if (filter == "") { location.reload(); }})
      
    .keyup( function () {$(this).change();}); 
  }

  $(function () {
    filterList($("#form1"), $('ul.tdlist'));
  });
}(jQuery));
